/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ViewAgegroupDlg.java
 *
 * Created on May 5, 2010, 8:32:06 AM
 */
package com.aptech.childcare.gui;

import com.aptech.childcare.buz.ChildcareBuz;
import com.aptech.childcare.components.ColumnData;
import com.aptech.childcare.components.ObjectTableModel;
import com.aptech.childcare.entities.ClassChild;
import java.awt.Image;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author Xuan Hieu
 */
public class ViewClassDlg extends javax.swing.JDialog{

    private ChildcareBuz buz = new ChildcareBuz();
    private ObjectTableModel tableModel;
    private ArrayList<ClassChild> cla = new ArrayList<ClassChild>();
    int confirm = 0, id = 0;
    // Table's headers
    private JTable headerTable;
    // Index of the selected row
    int index = -1;
    public static int claID;
    // public static String claID1;
    AddNannyDlg add;

    /** Creates new form ViewAgegroupDlg */
    public ViewClassDlg(AddNannyDlg add, boolean modal) throws IOException {
        super(add, modal);
        this.add = add;
        ImageIcon icon = new ImageIcon(getClass().getResource("../icon/logo.png"));
        Image image = icon.getImage();
        setIconImage(image);
        try {
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        }
        initComponents();
        loadtableClass();
        setLocationRelativeTo(null);
    }

    /**
     * 
     */
    public void loadtableClass() throws IOException {
        cla = buz.findClass();
        ColumnData[] columns = {
            new ColumnData("ID", 50, SwingConstants.LEFT, 1),
            new ColumnData("Name", 50, SwingConstants.LEFT, 2),
            new ColumnData("Agegroup", 50, SwingConstants.LEFT, 3),
            new ColumnData("Note", 50, SwingConstants.LEFT, 4),};
        tableModel = new ObjectTableModel(tbClass, columns, cla);
        headerTable = tableModel.getHeaderTable();

        // Create numbering column
        headerTable.createDefaultColumnsFromModel();
        tbClass.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        // Put it in a viewport that we can control a bit
        JViewport viewport = new JViewport();

        // Display numbering column
        viewport.setView(headerTable);
        viewport.setPreferredSize(headerTable.getMaximumSize());

        scrClass.setRowHeader(viewport);
        scrClass.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerTable.getTableHeader());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        scrClass = new javax.swing.JScrollPane();
        tbClass = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        lsNannylist = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        btnAdd = new javax.swing.JButton();

        setResizable(false);
        setTitle("View Detail Age Group");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jPanel1.setMinimumSize(new java.awt.Dimension(640, 189));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 255)));
        jPanel2.setMinimumSize(new java.awt.Dimension(500, 230));
        jPanel2.setPreferredSize(new java.awt.Dimension(500, 277));
        jPanel2.setLayout(new java.awt.GridBagLayout());

        scrClass.setPreferredSize(new java.awt.Dimension(200, 237));

        tbClass.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tbClass.setPreferredSize(new java.awt.Dimension(400, 128));
        scrClass.setViewportView(tbClass);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.8;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(20, 6, 18, 6);
        jPanel2.add(scrClass, gridBagConstraints);

        jScrollPane2.setPreferredSize(new java.awt.Dimension(100, 130));

        lsNannylist.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nanny", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(153, 153, 255))); // NOI18N
        lsNannylist.setMaximumSize(new java.awt.Dimension(80, 0));
        lsNannylist.setMinimumSize(new java.awt.Dimension(80, 0));
        lsNannylist.setPreferredSize(new java.awt.Dimension(80, 0));
        jScrollPane2.setViewportView(lsNannylist);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.insets = new java.awt.Insets(20, 6, 18, 6);
        jPanel2.add(jScrollPane2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        jPanel1.add(jPanel2, gridBagConstraints);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("View Detail Class");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        jPanel1.add(jLabel1, gridBagConstraints);

        jPanel3.setLayout(new java.awt.GridBagLayout());

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/aptech/childcare/icon/accept.png"))); // NOI18N
        btnAdd.setText("Add");
        btnAdd.setMaximumSize(new java.awt.Dimension(85, 25));
        btnAdd.setMinimumSize(new java.awt.Dimension(85, 25));
        btnAdd.setPreferredSize(new java.awt.Dimension(85, 25));
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(btnAdd, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(20, 10, 22, 10);
        jPanel1.add(jPanel3, gridBagConstraints);

        add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        // TODO add your handling code here:
        int n = tbClass.getSelectedRow();
        if (n == -1) {
            JOptionPane.showMessageDialog(this, "Choose Class to View");
            return;
        }
        index = tbClass.getSelectedRow();
        claID = cla.get(index).getClassID();
        add.txtClassID.setText(String.valueOf(claID));
        this.dispose();
    }//GEN-LAST:event_btnAddActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    ViewClassDlg dialog = new ViewClassDlg(new AddNannyDlg((MainFrm) new javax.swing.JFrame(), true), true);
                    dialog.setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(ViewClassDlg.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList lsNannylist;
    private javax.swing.JScrollPane scrClass;
    private javax.swing.JTable tbClass;
    // End of variables declaration//GEN-END:variables
}
